<!DOCTYPE html>
<html>
<head>
  <title>地址维护</title>
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <!-- head 中 -->
  <link rel="stylesheet" th:href="@{/jquery-weui/lib/weui.css}">
  <link rel="stylesheet" th:href="@{/jquery-weui/css/jquery-weui.css}">
  <link rel="stylesheet" th:href="@{/jquery-weui/css/demos.css?t=12}">
  <link rel="stylesheet" th:href="@{/css/h5style.css}">
  <style>
    html{
      height: 100%;

    }
    body{
      width: 100%;
      height:100%;
    }
    *{
      margin: 0;
      padding: 0;
    }
    .bd{
      width: 100%;
      height:90%;
      overflow-y: scroll;
    }
    /* 修改标题的文字大小 */
    .weui-dialog__title {
      font-size: 24px;
    }
    .weui-dialog__bd {
      font-size: 20px;
    }
    /* 修改按钮的文字大小和内边距 */
    .weui-dialog__btn {
      font-size: 20px;
      padding: 10px 20px;
    }
    .weui-cell__bd{
      height: 50px;
      line-height: 50px;
    }
    .weui-input{
      height: 50px;
      color: #333333;
      font-size: 22px;
    }
  </style>
</head>

<body ontouchstart class="only-bg-color">
<div style="width: 100%;height: 50px;position: fixed;top: 0px;z-index: 999997">
  <div class="weui-search-bar" id="searchBar" style="background-color: white;border: none;height: 50px;">
    <form class="weui-search-bar__form" autocomplete="off">
      <div class="weui-search-bar__box" style="background-color: #f3f3f3">
        <i class="weui-icon-search"></i>
        <input type="search" class="weui-search-bar__input" style="background-color: #f3f3f3" id="searchInput" name="searchInput" placeholder="请输入姓名/手机/公司名称" value="" required="required" onkeyup="queryAddr('1','2','query');">
        <a href="javascript:" class="weui-icon-clear" id="searchClear" onclick="on_query_cancel();"></a>
      </div>
      <label class="weui-search-bar__label" id="searchText" style="background-color: #f3f3f3">
        <i class="weui-icon-search" style="background-color: #f3f3f3"></i>
        <span>请输入姓名/手机/公司名称</span>
      </label>
    </form>
  </div>
</div>
<div style="height: 50px;"></div>
<div id="queryList" class="div-search-result" style="z-index: 999998">
</div>

<input id="pageTotal" name="pageTotal" value="" type="hidden">
<input id="pageCurrent" name="pageCurrent" value="" type="hidden">
<div id="addrList" style="margin: 8px;">
</div>
<div class="page-load" id="loading-div">
  <img id="page-load-img" src="/stamp/image/gif/loading.gif" style="display: none">

</div>


<div style="height: 30px;"></div>
<div style="position: fixed;bottom: 130px;width: 100%;height: 50px;z-index: 999999">
  <div style="text-align: center;width: 100%;">
    <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" style="height: 45px;font-size: 14pt" onclick="add_addr('2');">新增地址</a>&nbsp;
    <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" style="height: 45px;font-size: 14pt" onclick="on_close_popup();">关闭页面</a>
  </div>
</div>
</body>
<!-- body 最后 -->
<script type="text/javascript" th:src="@{/jquery-weui/lib/jquery-2.1.4.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/jquery-weui/lib/fastclick.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/jquery-weui/js/jquery-weui.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/jsfiles/crypto-js.min.js?t=1}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/jsfiles/com.js?t=12}" charset="utf-8"></script>
<script>
  $(function() {
    FastClick.attach(document.body);
  });
  var adminUrl = "[[${adminUrl}]]";
  //后端地址
  var url = "[[${serverUrl}]]/stamp/h5/api/";
  //图片显示
  var url1 = "[[${serverUrl}]]/stamp/tp/";

  var dz = window.location.href;
  dz = dz.replace(/&/g, "$");
  function init_data(){
    $.showLoading("数据加载中...");
    var jsonData = {
      lx:"2",
      timestamp:new Date().getTime()
    };
    var sendStr = {
      data:encrypt_str(JSON.stringify(jsonData),localStorage.getItem("a_h5"),localStorage.getItem("b_h5"))
    };
    $.ajax({
      type:"post",
      url:url+"addr_query",
      data:JSON.stringify(sendStr),
      dataType:"json",
      timeout : 10*1000, //超时时间设置，单位毫秒
      crossDomain: true,
      contentType: 'application/json;charset=UTF-8',
      headers: {
        "token": localStorage.getItem("token_h5")
      },
      beforeSend: function(request) {
        request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
      },
      success:function(result){
        if (result.code==0) {
          let rtn = decrypt_str(result.data, localStorage.getItem("a_h5"), localStorage.getItem("b_h5"));
          console.info("rtn:"+rtn);
          let d = JSON.parse(rtn);
          $("#pageTotal").val(d.pageTotal);
          $("#pageCurrent").val(d.pageCurrent);
          var zys = d.pageTotal*1;
          var dqy = d.pageCurrent*1;
          if (dqy<zys){
            var nr = "";
            nr = "<span id=\"page-load-span\" onclick=\"loadNext("+dqy+");\">点击加载下一页</span>";
            $("#loading-div").html(nr)
          }
          var str="";
          if (!is_null(d.tWxAddressBookL) && d.tWxAddressBookL.length>0){
            d.tWxAddressBookL.forEach(function(item){
              str+="  <div class=\"weui-panel weui-panel_access div-yuanjiao\">\n" +
                      "    <div class=\"weui-panel__bd\" onclick=\"set_addr('"+item.name+"','"+item.dh+"','"+item.fullAddress+"','"+item.lsh+"','2');\">\n" +
                      "      <div class=\"weui-media-box weui-media-box_text\">\n" +
                      "        <h4 class=\"weui-media-box__title\" style=\"color: #333333;font-size: 20pt\">"+item.name+"&nbsp;&nbsp;"+item.dh+"</h4>\n" +
                      "        <p class=\"weui-media-box__desc\" style=\"color: #999999;font-size: 16pt\">"+item.fullAddress+"</p>\n" +
                      "      </div>\n" +
                      "    </div>\n" +
                      "    <div class=\"weui-panel__ft\">\n" +
                      "      <div class=\"weui-cell weui-cell_link\">\n" +
                      "        <table style=\"width: 100%;collapse: collapse;border-spacing: 0px;left: 0px;color: #666666\">\n" +
                      "          <tr>\n" +
                      "            <td onclick=\"set_default("+item.lsh+");\">\n";
                      if (item.isDefault==1){
                        str+="              <img id=\"is_check_img\" src=\"/stamp/image/ico/check.png\" style=\"vertical-align:middle\" width=\"16\">&nbsp;<span style=\"font-size: 13pt;vertical-align:middle\">设为默认地址</span>\n";
                      }else{
                        str+="<img  id=\"is_check_img\" src=\"/stamp/image/ico/nocheck.png\" style=\"vertical-align:middle\" width=\"16\">&nbsp;<span style=\"font-size: 13pt;vertical-align:middle\">设为默认地址</span>\n";
                      }
                      str+="            </td>\n" +
                      "            <td style=\"text-align: right\">\n" +
                      // "              <img src=\"/stamp/image/ico/xiugai.png\" style=\"vertical-align:middle\" width=\"12\" onclick=\"on_edit("+item.lsh+")\"><span onclick=\"on_edit("+item.lsh+")\" style=\"font-size: 12px;vertical-align:middle\">编辑</span>&nbsp;\n" +
                      // "              <img src=\"/stamp/image/ico/del.png\" style=\"vertical-align:middle\" width=\"12\" onclick=\"on_del("+item.lsh+")\"><span onclick=\"on_del("+item.lsh+")\" style=\"font-size: 12px;vertical-align:middle\">删除</span>&nbsp;&nbsp;\n" +
                      "            </td>\n" +
                      "          </tr>\n" +
                      "        </table>\n" +
                      "      </div>\n" +
                      "    </div>\n" +
                      "  </div>";
            });
          }else{
            str+="<div style=\"width: 100%;text-align: center;\" id=\"no-data-div\">\n" +
                    "  <div style=\"height: 50px;\"></div>\n" +
                    "  <div><img id=\"page-load-img\" src=\"/stamp/image/ico/kongdizhi.png\" width=\"64\" height=\"64\"></div>\n" +
                    "  <div>地址簿空空如也</div>\n" +
                    "</div>";
          }
          $("#addrList").html(str);
        }
      },
      error:function(result){

      },complete:function(){
        $.hideLoading();
      }
    });
  }

  init_data();

  /*新增地址,增加一个回调区分的名称*/
  function add_addr(lx)
  {
    window.location.href=adminUrl+"/h5/addr/add?callback=addrquery&lx="+lx;
  }
  /*修改地址,增加一个回调区分的名称*/
  function on_edit(id)
  {
    window.location.href=adminUrl+"/h5/addr/update?callback=addrquery&id="+id+"&lx=2";
  }
  /*选择了地址后的回写*/
  function set_addr(name,tel,address,lsh,lx)
  {
    parent.set_addr(name,tel,address,lsh,lx)
  }
  /*关闭页面*/
  function on_close_popup()
  {
    parent.$.closePopup();
  }
  /*设为默认地址*/
  function set_default(id)
  {
    $.ajax({
      url: url+"addr_default",
      type: 'POST',
      data:"lx=2&id="+id+"&token="+localStorage.getItem("token_h5"),
      timeout: 60000,
      error: function(XMLHttpRequest, textStatus, errorThrown)
      {

      },
      success: function(htmlStr)
      {
        window.location.reload();
      }
    });
  }
</script>

</body>
</html>
